Telegram Group & Telegram Channel
Converts a string to kebab case.

๐Ÿ‘‰Use re.sub() to replace any - or _ with a space, using the regexp r"(_|-)+".

๐Ÿ‘‰Use re.sub() to match all words in the string, str.lower() to lowercase them.

๐Ÿ‘‰Finally, use str.join() to combine all word using - as the separator.

CODE:

from re import sub

def kebab(s):
return '-'.join(
sub(r"(\s|_|-)+"," ",
sub(r"[A-Z]{2,}(?=[A-Z][a-z]+[0-9]*|\b)|[A-Z]?[a-z]+[0-9]*|[A-Z]|[0-9]+",
lambda mo: ' ' + mo.group(0).lower(), s)).split())

Examples

kebab('camelCase') # 'camel-case'

kebab('some text') # 'some-text'

kebab('some-mixed_string With spaces_underscores-and-hyphens')
# 'some-mixed-string-with-spaces-underscores-and-hyphens'

kebab('AllThe-small Things') # 'all-the-small-things'

Share and Support
@Python_Codes



tg-me.com/python_codes/168
Create:
Last Update:

Converts a string to kebab case.

๐Ÿ‘‰Use re.sub() to replace any - or _ with a space, using the regexp r"(_|-)+".

๐Ÿ‘‰Use re.sub() to match all words in the string, str.lower() to lowercase them.

๐Ÿ‘‰Finally, use str.join() to combine all word using - as the separator.

CODE:

from re import sub

def kebab(s):
return '-'.join(
sub(r"(\s|_|-)+"," ",
sub(r"[A-Z]{2,}(?=[A-Z][a-z]+[0-9]*|\b)|[A-Z]?[a-z]+[0-9]*|[A-Z]|[0-9]+",
lambda mo: ' ' + mo.group(0).lower(), s)).split())

Examples

kebab('camelCase') # 'camel-case'

kebab('some text') # 'some-text'

kebab('some-mixed_string With spaces_underscores-and-hyphens')
# 'some-mixed-string-with-spaces-underscores-and-hyphens'

kebab('AllThe-small Things') # 'all-the-small-things'

Share and Support
@Python_Codes

BY Python Codes


Warning: Undefined variable $i in /var/www/tg-me/post.php on line 283

Share with your friend now:
tg-me.com/python_codes/168

View MORE
Open in Telegram


Python Codes Telegram | DID YOU KNOW?

Date: |

Unlimited members in Telegram group now

Telegram has made it easier for its users to communicate, as it has introduced a feature that allows more than 200,000 users in a group chat. However, if the users in a group chat move past 200,000, it changes into "Broadcast Group", but the feature comes with a restriction. Groups with close to 200k members can be converted to a Broadcast Group that allows unlimited members. Only admins can post in Broadcast Groups, but everyone can read along and participate in group Voice Chats," Telegram added.

Python Codes from no


Telegram Python Codes
FROM USA